package tg.app.rj.payreqw;

import java.rmi.RemoteException;

import psdi.mbo.MAXTableDomain;
import psdi.mbo.MboRemote;
import psdi.mbo.MboSetRemote;
import psdi.mbo.MboValue;
import psdi.util.MXException;

/***
 * 
 * @author pzx
 *
 */
public class FldVendor extends MAXTableDomain{

	public FldVendor(MboValue mbv) {
		super(mbv);
		String attributename = mbv.getAttributeName();
	    setRelationship("COMPANIES", "");
	    String[] strFrom = { "COMPANY" };
	    String[] strTo = { attributename };
	    setLookupKeyMapInOrder(strTo, strFrom);
	}

	@Override
	public MboSetRemote getList() throws MXException, RemoteException {
		setListCriteria(" orgid = :orgid ");
		return super.getList();
	}
	@Override
	public void action() throws MXException, RemoteException {
		super.action();
		MboRemote mbo = this.getMboValue().getMbo();
		if(mbo!=null){
			MboSetRemote payouts = mbo.getMboSet("PAYREQOUR");
			if(!payouts.isEmpty()){
				for(int i = 0;i<payouts.count();i++){
					payouts.getMbo(i).delete();
					payouts.save();
				}
				payouts.save();
			}
			MboSetRemote payoutlines = mbo.getMboSet("PAYREQLINE_WW");
			if(!payoutlines.isEmpty()){
				for(int j = 0;j<payoutlines.count();j++){
					payoutlines.getMbo(j).delete();
					payoutlines.save();
				}
				payoutlines.save();
			}
			mbo.getThisMboSet().save();
		}
	}
}
